{% extends "base.html" %}
{% load i18n %}
{% block title %} Tu Negocio Empresarios - Agregar Productos Cliente{% endblock %}

{% block head-css-ext %}
    <link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}css/layout.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}css/jquery-ui.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}css/blue/style.css" media="print, projection, screen" />
{% endblock %}

{% block head-js-ext %}
    <script type="text/javascript" src="{{MEDIA_URL}}js/jquery.js"></script>
    <script type="text/javascript" src="{{MEDIA_URL}}js/jquery-ui.js"></script>
    <script type="text/javascript" src="{{MEDIA_URL}}js/jquery.tablesorter.js"></script>
    <script type="text/javascript" src="{{MEDIA_URL}}js/jquery.tablePagination.js"></script>
    <script type="text/javascript" src="{{MEDIA_URL}}js/jquery.translate.js"></script>  
    <script type="text/javascript" src="{{MEDIA_URL}}js/jquery.bgiframe.js"></script>
    <script type="text/javascript" src="{{MEDIA_URL}}js/date.format.js"></script> 
{% endblock %}

{% block head-js-embedded %}
    <script type="text/javascript">
        $(document).ready(function(){
            var options = {
                firstArrow : (new Image()).src="{{MEDIA_URL}}img/icons/first.png",
                prevArrow : (new Image()).src="{{MEDIA_URL}}img/icons/prev.png",
                lastArrow : (new Image()).src="{{MEDIA_URL}}img/icons/last.png",
                nextArrow : (new Image()).src="{{MEDIA_URL}}img/icons/next.png"
            }	
            $("button, input:submit", ".enviar").button();
	  
            $("#prestamos").tablesorter({widthFixed: true,  widgets: ['zebra'], headers: { 0 : {sorter: false}, 1 : {sorter: false}, 2 : {sorter: false} } }).tablePagination(options);
		
            $("#tablePagination").translate('en', 'es');
	  
            $("select#tipoprestamo").change(function(){
                var valor = $(this).val();
                if (valor != 0)
                {
                    $.getJSON("/ajax/buscar-inventario/"+ $(this).val()+ "/", function(data){
            	
                        var options = '';
                        for (var i = 0; i < data.length; i++)
                        {
                            options += '<tr>' +
                                            '<td>' + data[i].fields['descripcion'] + '</td>' +
                                            '<td align="right">' + data[i].fields['existencias'] + '</td>' +
                                            '<td align="center">' + '<input type="checkbox" name="agregar" value="' + parseInt(data[i].pk) + '" id="event">' + '</td>' +
                                        '</tr>';			
                        }
                        $("#prestamos tbody").html(options).show();			  
                    });			
                }
                else
                {
                    $("#prestamos tbody").hide();
                }
            });
	  
            $("form").submit(function(){
                if (!isCheckedById("event"))
                {
                    alert ("Seleccione al menos uno para devolución");
                    return false;
                }
                else
                {
                    return true; //submit the form
                }
            });
	  
            function isCheckedById(id)
            {
                var checked = $("input[id="+id+"]:checked").length;
                if (checked == 0)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }	
        });     
    </script>
{% endblock %}

{% block content-box1 %}
    {% if msg_list %}
        {% for message in msg_list %}
        	{{ message }}
        {% endfor %}
    {% endif %}
    <br><br>
    <select id="tipoprestamo" name="tipoprestamo">
        <option value="" selected="selected">-----------------------</option>
        <option value="nutrilite">Nutrilite</option>
        <option value="moiskin">Moiskin</option>
        <option value="ertia">Ertia</option>
        <option value="glister">Glister</option>
        <option value="tolsom">Tolsom</option>
        <option value="fragancias">Fragancias</option>
        <option value="aseo">Cuidado del Hogar</option>
        <option value="icook">iCook</option>
        <option value="promociones">Promociones</option>
    </select>
    <br><br>
    <form method="POST" id="testform">{% csrf_token %}
        <table id="prestamos" class="tablesorter">
            <thead>
                <tr align="center">                    
                    <th>descripcion</th>
                    <th>Existencias Disponibles</th>                                     
                    <th>Marcar para Agregar</th>
                </tr>            
            </thead>   
            <tbody>
            </tbody>
        </table>
        <br>
        <div align="center" class="enviar">
            <input type="submit" name="devolverprestamo" id="devolver_prestamo" value="Aplicar Devolucion"></p>
        </div>
    </form>  
{% endblock %}

{% block content-colum2 %}
    {% if user.is_authenticated %}
        <ul>
            <li><a href="{% url index %}">{% trans "Home" %}</a></li>
            <li><a href="{% url empresarios %}">Empresarios</a></li>
            
        </ul>
    {% endif %}   
{% endblock %}
